package com.nervenets.template.controller.wealth;

import com.nervenets.general.entity.ResponseResult;
import com.nervenets.general.jwt.util.JwtUtils;
import com.nervenets.general.web.BaseEntityController;
import com.nervenets.template.controller.user.params.WealthFlowPagingParams;
import com.nervenets.template.controller.wealth.params.SurplusParams;
import com.nervenets.template.controller.wealth.params.WealthFlowFormParams;
import com.nervenets.template.hibernate.domain.user.WealthFlow;
import com.nervenets.template.service.WealthFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@Api(value = "资产接口v1", tags = "资产相关接口")
@RestController
@RequestMapping("/api/wealth")
public class WealthFlowController extends BaseEntityController<WealthFlow, WealthFlowService, WealthFlowFormParams, WealthFlowPagingParams, WealthFlow, WealthFlow> {

    @ApiOperation(value = "获取用户资产余额，targetId为对象的ID")
    @PostMapping("/surplus")
    public ResponseEntity<ResponseResult<Long>> surplus(@Valid @RequestBody SurplusParams params) {
        return successMessage(service.getSurplus(
                params.getUserId() > 0 ? params.getUserId() : JwtUtils.getUser().getId(),
                params.getWealthType()
        ));
    }

    @ApiOperation(value = "获取用户资产分布，targetId为对象的ID")
    @PostMapping("/map")
    public ResponseEntity<ResponseResult<Map>> map(@Valid @RequestBody SurplusParams params) {
        return successMessage(service.getMap(
                params.getUserId() > 0 ? params.getUserId() : JwtUtils.getUser().getId(),
                params.getWealthType()
        ));
    }
}
